package parser;

import java.util.Vector;

public class PQuery{
//attribute
	public Vector<String> select;
	public Vector<String> from;
	public Vector<String> where;
	//public QueryTree qt;
//method
	PQuery(String cmd){
		decompose(cmd);
		//qt = new QueryTree(select, from, where);
		//qt.build_tree();
	}
	void decompose(String cmd){
		String []sAry;
		String []ss;
		sAry = cmd.split("SELECT\\s+");
		sAry = sAry[1].split("\\s+FROM\\s+");
		//select
		ss = sAry[0].split("\\s*\\,\\s*");
		select = new Vector<String>(ss.length);
		for(int i=0; i<ss.length; i++)
			select.add(ss[i]);
		//from
		sAry = sAry[1].split("\\s+WHERE\\s+");
		ss = sAry[0].split("\\s*\\,\\s*");
		from = new Vector<String>(ss.length);
		for(int i=0; i<ss.length; i++)
			from.add(ss[i]);
		//where
		if(sAry.length>1){
			ss = sAry[1].split("\\s+AND\\s+");
			where = new Vector<String>(ss.length);
			for(int i=0; i<ss.length; i++)
				where.add(ss[i]);
		}
		//System.out.print("");
	}
}
